const express=require('express');
const mysql=require('mysql');
const urlobj=require('url');
//引用自定义
//const commte=require('../../libs/commtle');
//链接数据库
var db=mysql.createPool({
    host:'localhost',
    user:'root',
    password:'',
    database:'leasedb'
});

//业务逻辑
module.exports = function() {
    var router = express.Router();

    //查询最新动态
    router.post('/AddPrimaryClassification.html',function(req,res){
        console.log(3);
        db.query('INSERT INTO forumainfo(forumAId, forumAName) VALUES (0,"'+req.body.shrpitname+'")',function (err,data) {
            if(err){
                console.log(2);
                res.status(400).send('<script>alert("程序出错");window.location.href="400.html";</script>')
            }else{
                res.status(200).send('<script>alert("新增成功");window.location.href="PrimaryClassification.html";</script>')
            }
        })
    });
//开始渲染后台首页
    router.get('/AddPrimaryClassification.html',function(req,res,next){
        res.render("forum/AddPrimaryClassification.ejs");
    });


    return router;
}